package com.dandandog.framework.faces.model.tree;

import com.dandandog.framework.common.model.ITree;
import lombok.Data;
import org.primefaces.model.TreeNode;

import java.io.Serializable;
import java.util.List;

/**
 * @Author: JohnnyLiu
 * @Date: 2021/10/29 16:19
 */
@Data
public class TreeNodeState implements Serializable {

    private TreeNode<? extends ITree>[] selected;

    private boolean edit;

    private boolean expand;

    @SafeVarargs
    TreeNodeState(Boolean edit, boolean expand, TreeNode<? extends ITree>... selected) {
        this.selected = selected;
        this.edit = edit;
        this.expand = expand;
    }

    public static TreeNodeState.TreeNodeStateBuilder builder() {
        return new TreeNodeState.TreeNodeStateBuilder();
    }

    public static class TreeNodeStateBuilder {
        private TreeNode<? extends ITree>[] selected;
        private boolean edit;
        private boolean expand;

        TreeNodeStateBuilder() {
        }

        public TreeNodeState.TreeNodeStateBuilder selected(TreeNode<? extends ITree>... selected) {
            this.selected = selected;
            this.edit = false;
            return this;
        }

        public TreeNodeState.TreeNodeStateBuilder selectedEditing(TreeNode<? extends ITree>... selected) {
            this.selected = selected;
            this.edit = true;
            return this;
        }


        public TreeNodeState.TreeNodeStateBuilder expand(boolean expand) {
            this.expand = expand;
            return this;
        }

        public TreeNodeState.TreeNodeStateBuilder edit(boolean edit) {
            this.edit = edit;
            return this;
        }

        public TreeNodeState build() {
            return new TreeNodeState(this.edit, this.expand, this.selected);
        }
    }


}
